<%inherit file='/base.mako' />
<%def name="title()">Project Details for ${c.project.name|h}</%def>
<%def name="stylesheets()">${h.stylesheet_link_tag('project')}</%def>
<%def name="javascripts()">
${h.javascript_include_tag('project')}
<script>
	function check_note_length(note){
		
		var note = document.getElementById(note);
		
		if (note.value.length >= 1500) {
			alert('Please use separate notes for lengthy posts');
			note.focus();
			return false;
		}

		return true;
	}
</script>
</%def>


	<h2 id="project_name">${c.project.name|h}</h2>
    % if c.project_editable:
	<div id="status">
	    % if c.project.archived:
	    <span>Archived</span>
	    % else:
	    ${h.select('status', h.status_options(c.project.status), onchange="update_project()", id="select_status")}
        % endif
		<br/>
	</div>
	% else:
	<div class="${h.selector(c.project.delayed, "bad", "good")} id="status">${c.project.status_code}</div>
	% endif
	
	<div id="description" onmouseover="show_inline('description_edit_link')" onmouseout="hide('description_edit_link')">
		<span id="description_content">${c.project.description}</span>
		% if c.project_editable:
		${h.link_to_function('edit', "toggle('edit_description');toggle('description')", id='description_edit_link', style='display:none;')}
		% endif
	</div>
	
	<div id="edit_description" style="display: none;">
		<textarea id="ta_description" name="description" rows="3" cols="70">${c.project.description}</textarea><br/>
		<a href="#" onclick="update_project();toggle('edit_description');toggle('description');hide('description_edit_link');return false;">save</a>
		<a href="#" onclick="toggle('edit_description');toggle('description');hide('description_edit_link')">cancel</a>
	</div>
	
	<br/>
	
	<div id="contact" onmouseover="show_inline('edit_contact_link');" onmouseout="hide('edit_contact_link');">
		<b>Contact:</b>
		<span id="contact_content">${h.mail_to(c.project.contact.email, c.project.contact.username)}</span>
		% if c.project_editable:
		${h.link_to_function('edit', "toggle('contact');toggle('edit_contact')")}
        % endif
	</div>
	
	<div style="display: none" id="edit_contact">
		<b>Contact:</b>
		${h.select('contact_id', h.user_options(c.project.contact_id), onchange="update_project(); window.location.reload()")}
		${h.link_to_function('cancel', "toggle('edit_contact');toggle('contact');hide('edit_contact_link')")}
	</div>
	
	<ul id="toggle_links">
	    % if c.project.subprojects:
	    <li>${h.link_to_function('sub-projects', "toggle('project_subprojects');switch_link('subprojects')", 
	                         id="subprojects_switch", class_="on")}</li>
	    % endif
	
	    % if c.project.parent_project:
		<li>${h.link_to_function('parent project', "toggle('project_parent');switch_link('parent')", id="parent_switch", class_="on")}</li>
	    % endif

		<li>${h.link_to_function('issues', "toggle('project_issues');switch_link('issues')", id="issues_switch", class_="on")}</li>
		<li>${h.link_to_function('risks', "toggle('project_risks');switch_link('risks')", id="risks_switch", class_="on")}</li>
		<li>${h.link_to_function('notes', "toggle('project_notes');switch_link('notes')", id="notes_switch", class_="on")}</li>
		<li>${h.link_to_function('questions', "toggle('project_questions');switch_link('questions')", id="questions_switch", class_="on")}</li>
		<li>${h.link_to_function('files', "toggle('project_files');switch_link('files')", id="files_switch", class_="on")}</li>
	</ul>
	
	% if c.project.subprojects:
	<div id="project_subprojects">
		<h3>Sub Projects</h3>
		<ul id="subprojects">
		    % for subproject in c.project.subprojects:
			<li>
			    ${h.link_to(subproject.name, h.url_for(action='select', project_id=subproject.id))} (${subproject.status_code})
			</li>
			% endfor
		</ul>
	</div>
	% endif
	
	% if c.project.parent_project:
	<div id="project_parent">
		<h3>Parent Project</h3>
		This project is a sub-project of ${h.link_to(c.project.parent_project.name, h.url_for(action='select', project_id=c.project.parent_project.id))}.
	</div>
	% endif
	
	<div id="project_issues">
		<h3>Issues</h3>
		% if not c.project.open_issues:
		<p>This project has no open issues.</p>		
		% endif
		
        <!--<div id="issues_container" py:content="issues_widget.display(issues=project.issues, show_closed=show_closed_issues)" />-->
		
		${h.link_to_function('add issue', "toggle('new_issue');fcs('new_issue_description')")}
		% if c.project.issues:
		${h.link_to(h.selector(c.show_closed_issues, "hide closed issues", "show closed issues"), h.url_for(action='toggle_closed_issues'))}
		% endif
		<div id="new_issue" style="display: none;">
			<table>
				<tr>
					<td><b>Impact</b></td>
					<td>
					    ${h.select('impact', h.impact_options(), id="new_issue_impact")}
					</td>
				</tr>
			</table>
			<b>Description</b><br/>
			${h.text_area('description', rows=4, cols=70, id="new_issue_description")}<br/>
			${h.link_to_function('add', 'add_issue()')}
			${h.link_to_function('cancel', "toggle('new_issue')")}
		</div>
	</div>
	
	<div id="project_risks">
		<h3>Risks</h3>
		% if not c.project.open_risks:
		<p>This project has no open risks.</p>
		% endif
		<!--<div id="risks_container" py:content="risks_widget.display(risks=project.risks, show_closed=show_closed_risks)" />-->

        ${h.link_to_function('add risk', "toggle('new_risk');fcs('new_risk_description')")}
        % if c.project.risks:
        ${h.link_to(h.selector(c.show_closed_risks, 'hide closed risks', 'show closed risks'), h.url_for(action='toggle_closed_risks'))}
		% endif
				
		<div id="new_risk" style="display: none;">
			<table>
				<tr>
					<td><b>Impact</b></td>
					<td>
					    ${h.select('impact', h.impact_options(), id="new_risk_impact")}
					</td>
					<td width="5"></td>
					<td><b>Chance</b></td>
					<td>
                        ${h.select('chance', h.chance_options(), id="new_risk_chance")}
					</td>
				</tr>
			</table>
			<b>Description</b><br/>
			${h.text_area('description', rows=4, cols=70, id="new_risk_description")}<br/>
			${h.link_to_function('add', 'add_risk()')}
			${h.link_to_function('cancel', "toggle('new_risk')")}
		</div>
	</div>
	
	<div id="project_notes">
	    <h3>${h.selector(c.show_all_notes, 'All Progress Notes', 'Recent Progress Notes')}</h3>
	    % if not c.project.notes:
	    <p id="no_notes_message">This project has no notes.</p>
	    % endif
		
		<ul id="notes">
		% for note in h.selector(c.show_all_notes, c.project.notes, c.project.recent_notes):
        <%include file='/project/note.mako' args='note=note' />
		% endfor
		</ul>
				
		${h.link_to_function('add note', "toggle('new_note'); fcs('ta_new_note')")}
        ${h.link_to(h.selector(c.show_all_notes, 'show recent notes', 'show all notes'), h.url_for(action='toggle_show_all_notes'))}
		<div id="new_note" style="display: none;">
		  <b>Note</b><br/>
		  ${h.text_area('note', rows=8, cols=70, id="ta_new_note")}<br/>
			${h.link_to_function('add', "if (check_note_length('ta_new_note')) {create_new_note();}")}
			${h.link_to_function('cancel', "toggle('new_note')")}
		</div>
	</div>
	
	<div id="project_questions">
		<h3>Questions</h3>
		
		% if not c.project.questions:
		<p>This project has no questions.</p>
		% endif
		
        <span py:replace="questions_widget.display(questions=project.questions)" />
		
		${h.link_to_function('ask question', "toggle('new_question'); fcs('new_question_text')")}
		<div id="new_question" style="display: none;">
			<b>Question</b><br/>
			${h.text_area('name', rows=5, cols=80, id="new_question_text")}<br/>
			${h.link_to_function('add', "add_question()")}
			${h.link_to_function('cancel', "toggle('new_question')")}
		</div>
	</div>
	
	
	<div id="project_files">
		<h3>Project Files</h3>
		% if not c.project.files:
		<p>This project has no files.</p>
		% endif
		
		<ul id="files">
		    % for file in c.project.files:
			<li class="file" onmouseover="show_inline('remove_file_link_$file.id');" onmouseout="hide('remove_file_link_$file.id'); ">
				<div class="file_content">
				     <div>${link_to(file.filename, '/files/%s' % file.systemfilename, popup=True)}</div>
					<div class="file_info">
						<span>
						Posted by ${h.mail_to(file.creator.email, file.creator.username, class_="file_creator")}
						on {file.created}
						</span>
						% if file.creator == c.current_user or h.in_group('admin'):
                        ${h.link_to('remove', h.url_for(action='remove_file', id=file.id), id="remove_file_link_%s" % file.id, style="display:none;")}
						% endif
					</div>
				</div>
			</li>
		    % endfor
		</ul>
		
		${h.link_to_function('add file', "toggle('new_file'); fcs('ta_new_file')")}
		<div id="new_file" style="display: none;">
			${h.start_form(h.url_for(action='new_file'), multipart=True, id="form_new_file")}
				<b></b><br/>
				Upload File: ${h.file_field('file', id="ta_new_file")}<br/>
				${h.link_to_function('add', "submit('form_new_file')")}
				${h.link_to_function('cancel', "toggle('new_file')")}
		    ${h.end_form()}
		</div>
	</div>
	
	% if c.project_editable and not c.project.parent_project:
	<div id="archive_project">
        ${h.link_to(h.selector(c.project.archived, 'unarchive this project', 'archive this project'),      h.url_for(action='toggle_archive_project'))}	
	</div>
    % endif
